package p.ithorns.intergration.hz.client;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * RandomNumberTask
 * TODO ithorns
 *
 * @author Ht.L
 * @date 2023-11-21 09:13
 * @since 1.0.0
 */
@Slf4j
@Component
public class RandomNumberTask {

    private final Random random = new Random();

    @Autowired
    private HazelcastService hazelcastService;

    @Scheduled(fixedRate = 1000) // 每秒产生一个随机整数
    public void generateRandomNumber() {
        int number = random.nextInt(10);
        log.info("=====> Spring提交任务: {}", number);

        hazelcastService.submitAndCalculateSum(number);
    }

}